/*     */ package cc.s2m.web.s2mBlog.controller.admin;
/*     */ 
/*     */ import cc.s2m.util.BeanConverter;
/*     */ import cc.s2m.util.Page;
/*     */ import cc.s2m.web.s2mBlog.controller.base.BaseController;
/*     */ import cc.s2m.web.s2mBlog.pojo.ArticlesTags;
/*     */ import cc.s2m.web.s2mBlog.pojo.Tags;
/*     */ import cc.s2m.web.s2mBlog.service.IArticlesTags;
/*     */ import cc.s2m.web.s2mBlog.service.ITags;
/*     */ import cc.s2m.web.s2mBlog.vo.Expressions;
/*     */ import cc.s2m.web.s2mBlog.vo.VO;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller("admin_TagsController")
/*     */ @RequestMapping({"/admin/tags"})
/*     */ public class TagsController extends BaseController
/*     */ {
/*     */ 
/*     */   @Autowired
/*     */   private ITags tagsService;
/*     */ 
/*     */   @Autowired
/*     */   private IArticlesTags articlesTagsService;
/*     */ 
/*     */   @RequestMapping({"/list"})
/*     */   public String list(Model model, Tags bean, Integer page)
/*     */   {
/*  34 */     if (page == null) page = Integer.valueOf(1);
/*  35 */     Map map = new HashMap();
/*  36 */     if (bean != null) {
/*  37 */       map.putAll(BeanConverter.toMap(bean, false));
/*  38 */       model.addAttribute("bean", bean);
/*     */     }
/*  40 */     Page pageBean = this.tagsService.getPage(page.intValue(), 50, null, map);
/*  41 */     model.addAttribute("pageBean", pageBean);
/*  42 */     return "admin/tags";
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"/add"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public String add(Model model, Integer id) {
/*  47 */     if (id != null) {
/*  48 */       Tags bean = (Tags)this.tagsService.selectByPrimaryKey(id);
/*  49 */       model.addAttribute("bean", bean);
/*     */     }
/*  51 */     return "admin/tags_add";
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"/view"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public String view(Model model, Integer id) {
/*  56 */     if (id != null) {
/*  57 */       Tags bean = (Tags)this.tagsService.selectByPrimaryKey(id);
/*  58 */       model.addAttribute("bean", bean);
/*     */     }
/*  60 */     return "admin/tags_view";
/*     */   }
/*     */   @RequestMapping(value={"/save"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*     */   public String save(Model model, Tags bean) {
/*  66 */     if (bean == null) {
/*  67 */       return "empty";
/*     */     }
/*  69 */     if (bean.getId() == null)
/*     */     {
/*  71 */       Tags condition = new Tags();
/*  72 */       condition.setName(bean.getName());
/*  73 */       condition = (Tags)this.tagsService.getByCondition(condition);
/*  74 */       if (condition != null) {
/*  75 */         return "exists";
/*     */       }
/*  77 */       condition = new Tags();
/*  78 */       condition.setUrl(bean.getUrl());
/*  79 */       condition = (Tags)this.tagsService.getByCondition(condition);
/*  80 */       if (condition != null) {
/*  81 */         return "exists";
/*     */       }
/*  83 */       this.tagsService.insertSelective(bean);
/*     */     }
/*     */     else {
/*  86 */       Tags condition = new Tags();
/*  87 */       condition.setName(bean.getName());
/*  88 */       VO vo = new VO();
/*  89 */       vo.and(Expressions.ne("id", bean.getId()));
/*  90 */       condition = (Tags)this.tagsService.getByCondition(condition, vo);
/*  91 */       if (condition != null) {
/*  92 */         return "exists";
/*     */       }
/*  94 */       condition = new Tags();
/*  95 */       condition.setUrl(bean.getUrl());
/*  96 */       condition = (Tags)this.tagsService.getByCondition(condition, vo);
/*  97 */       if (condition != null) {
/*  98 */         return "exists";
/*     */       }
/* 100 */       this.tagsService.updateByPrimaryKeySelective(bean);
/*     */     }
/* 102 */     return "success";
/*     */   }
/*     */   @RequestMapping(value={"/del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*     */   public String del(Integer id) {
/* 108 */     Tags bean = (Tags)this.tagsService.selectByPrimaryKey(id);
/* 109 */     if (bean != null) {
/* 110 */       this.tagsService.deleteByPrimaryKey(id);
/*     */     }
/* 112 */     ArticlesTags condition = new ArticlesTags();
/* 113 */     condition.setTid(id);
/* 114 */     List<ArticlesTags> list = this.articlesTagsService.getList(condition, null);
/* 115 */     for (ArticlesTags atag : list) {
/* 116 */       this.articlesTagsService.deleteByPrimaryKey(atag.getId());
/*     */     }
/* 118 */     return "success";
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.controller.admin.TagsController
 * JD-Core Version:    0.6.1
 */